var start=Date.now(),cnt=0;
(function tick(){
    if(cnt>20)return;
    //nextTick 1毫秒内执行多次，更快
    process.nextTick(function(){
        console.log('tick:',cnt++,Date.now()-start);
        tick();
    });
})();
/*
 tick: 0 19
 tick: 1 21
 tick: 2 23
 tick: 3 23
 tick: 4 23
 tick: 5 23
 tick: 6 23
 tick: 7 23
 tick: 8 23
 tick: 9 23
 tick: 10 23
 tick: 11 23
 tick: 12 24
 tick: 13 24
 tick: 14 24
 tick: 15 24
 tick: 16 24
 tick: 17 24
 tick: 18 24
 tick: 19 24
 tick: 20 24
*/

var s2=Date.now(),c2=0;
(function timeout(){
    if(c2>=20)return;
    //setTimeout:1毫秒内最多执行一次，更慢
    setTimeout(function(){
        console.log('timeout:',c2++,Date.now()-s2);
        timeout();
    });
})();
/*
 timeout: 0 24
 timeout: 1 25
 timeout: 2 26
 timeout: 3 27
 timeout: 4 28
 timeout: 5 29
 timeout: 6 30
 timeout: 7 31
 timeout: 8 32
 timeout: 9 33
 timeout: 10 34
 timeout: 11 35
 timeout: 12 36
 timeout: 13 37
 timeout: 14 38
 timeout: 15 39
 timeout: 16 40
 timeout: 17 41
 timeout: 18 42
 timeout: 19 43
*/